package com.mata.worktime.service.user.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mata.worktime.dao.user.RoleResourceMapper;
import com.mata.worktime.entity.user.RoleResource;
import com.mata.worktime.service.user.RoleResourceService;

import java.util.ArrayList;
import java.util.List;


/**
 * @author earthchen
 * @date 2018/9/28
 **/
@Service
public class RoleResourceServiceImpl extends ServiceImpl<RoleResourceMapper, RoleResource>
    implements RoleResourceService
{
    @Autowired
    private RoleResourceMapper roleResourceMapper;

    /**
     * 删除对应角色的权限资源
     */
    @Override
    public void deleteRoleMenuByRoleId(Long roleId)
    {
        roleResourceMapper.deleteRoleMenuByRoleId(roleId);
    }

    /**
     * 插入角色的权限资源
     *
     * @param menuIds
     */
    @Override
    public void batchRoleResource(Long roleId, Long[] menuIds)
    {
        List<RoleResource> list = new ArrayList<>();
        for (Long resourceId : menuIds)
        {
            RoleResource rr = new RoleResource();
            rr.setRoleId(roleId);
            rr.setResourceId(resourceId);
            list.add(rr);
        }

        saveBatch(list);

//        roleResourceMapper.batchRoleResource(list);
    }
}
